<?php

require( "functions.php" );

$topNode = LoggerCreateXMLDocument();

if ( LoggerOpenDB() )
{
	if ( isset( $_POST[ "net_id" ], $_POST[ "logger_id" ], $_POST[ "record_time" ] ) )
	{
		$net_id = ( int ) $_POST[ "net_id" ];
		$logger_id = mysql_real_escape_string( rawurldecode( $_POST[ "logger_id" ] ) );
		$record_time = mysql_real_escape_string( rawurldecode( $_POST[ "record_time" ] ) );
		$sql = "UPDATE loggers SET update_count = update_count + 1 WHERE net_id = $net_id AND logger_id = '$logger_id'";
		if ( mysql_query( $sql ) && mysql_affected_rows() == 1 )
		{
			$sql = "SELECT * FROM nets WHERE net_id = $net_id AND record_time >= '$record_time'";
			LoggerAppendSelect( $sql, "nets", $topNode );
			$sql = "SELECT * FROM loggers WHERE net_id = $net_id";
			LoggerAppendSelect( $sql, "loggers", $topNode );
			$sql = "SELECT * FROM roster WHERE net_id = $net_id AND logger_id <> '$logger_id' AND record_time >= '$record_time'";
			LoggerAppendSelect( $sql, "roster", $topNode );
			$sql = "SELECT * FROM activity WHERE net_id = $net_id AND logger_id <> '$logger_id' AND record_time >= '$record_time'";
			LoggerAppendSelect( $sql, "activity", $topNode );
		}
		else
		{
			$error = "UPDATE loggers failure";
		}
	}
}
else
{
	$error = "DB open failure";
}

if ( isset( $error ) )
{
	LoggerAppendError( $topNode, $error );
}

$doc = $topNode->ownerDocument;
echo $doc->saveXML();

?>